<?php


namespace App\Models;

use Mockery\Exception;

class ElementModel extends Base
{

    protected $table = 'element';

    protected $primaryKey = 'e_id';

    public $timestamps = false;

    protected $fillable = [
        'estate_id', 'c_id', 'element_num', 'h_id'
    ];

    /**
     * Notes: 关联小区
     * User: lstink
     * Date: 2021/2/2
     * Time: 5:17 下午
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function community()
    {
        return $this->belongsTo(Community::class, 'c_id', 'community_id')->select('community_id,community_name');
    }

    /**
     * Notes: 关联物业
     * User: lstink
     * Date: 2021/2/2
     * Time: 5:17 下午
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function estate()
    {
        return $this->belongsTo(Property::class, 'estate_id', 'id');
    }

    /**
     * Notes: 关联楼栋
     * User: lstink
     * Date: 2021/2/5
     * Time: 11:08 上午
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function house()
    {
        return $this->belongsTo(HouseModel::class, 'h_id', 'h_id', 'join')->select('h_id,house_num')->orderBy('house_num');
    }

    /**
     * Notes: 关联楼层
     * User: lstink
     * Date: 2021/2/2
     * Time: 5:28 下午
     * @return \Illuminate\Database\Eloquent\Relations\hasMany
     */
    public function floor()
    {
        return $this->hasMany(FloorModel::class, 'e_id', 'e_id')->select('f_id,floor')->orderBy('floor');
    }
}
